package com.mycity.gamification;

import com.mycity.bean.Gamer;
import com.mycity.bean.User;

/**
 * The AchievementSystem class gives achievements to the user 
 * based on their experiences and past interactions.
 * @author  Ahmet Erdem
 * @version December 2013 
 */
public class AchievementSystem {
	
	private static final int NUM_ACHIEVEMENTS = 5;
	
	/**
	 * Updates user's achievements.
	 * Decides achievements based on the user's diamond/post and star/comment ratios,
	 * numbers, traveled locations and experiences.
	 * @param user user
	 * @param gamer information stored for gamification for a user
	 * @return updated user
	 */
	public static User update(User user, Gamer gamer){
		String[] achievements = new String[NUM_ACHIEVEMENTS];
		
		if(gamer.getNumComments()>=20&&(double)gamer.getNumStars()/gamer.getNumComments()>=0.6)
			achievements[0] = "Star Gatherer";
		
		if(gamer.getNumPosts()>=10&&gamer.getNumDiamonds()/gamer.getNumPosts()>=3)
			achievements[1] = "Shine Bright Like A Diamond";
		else if(gamer.getNumPosts()>=10&&gamer.getNumDiamonds()==0)
			achievements[2] = "Loser";
		
		if(gamer.getNumLocations()>=20)
			achievements[3] = "Traveller";
		
		if(gamer.maxExp)
			achievements[4] = "Top Contributer";
		
		user.setAchievements(achievements);
		user.setLevel(LevelCalculator.findLevel(gamer.getExperience()));
		
		return user;
		
	}

}
